package com.survey.demo.http.bean;

import android.media.MediaMetadataRetriever;
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.survey.demo.ui.activity.VideoSelectActivity;

import java.io.File;

public class HomeEntity implements Parcelable{

    private  String img;
    private  String title;
    private  String price;

    public boolean isUse() {
        return isUse;
    }

    public void setUse(boolean use) {
        isUse = use;
    }

    private boolean isUse;

    public static VideoSelectActivity.VideoBean newInstance(String videoPath) {
        int duration = 0;
        try {
            MediaMetadataRetriever retriever = new MediaMetadataRetriever();
            // 荣耀 LLD AL20 Android 8.0 出现：java.lang.IllegalArgumentException
            // 荣耀 HLK AL00 Android 10.0 出现：java.lang.RuntimeException：setDataSource failed: status = 0x80000000
            retriever.setDataSource(videoPath);
            duration = Integer.parseInt(retriever.extractMetadata
                    (MediaMetadataRetriever.METADATA_KEY_DURATION));
        } catch (RuntimeException e) {
            e.printStackTrace();
        }

        long size = new File(videoPath).length();
        return new VideoSelectActivity.VideoBean(videoPath, duration, size);
    }

    public String getImg() {
        return img;
    }

    public void setImg(String img) {
        this.img = img;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }
    public HomeEntity() {

    }
    public HomeEntity(String img, String title, String price,boolean isUse) {
        this.img = img;
        this.title = title;
        this.price = price;
        this.isUse = isUse;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.img);
        dest.writeString(this.title);
        dest.writeString(this.price);
        dest.writeBoolean(this.isUse);
    }

    protected HomeEntity(Parcel in) {
        this.img = in.readString();
        this.title = in.readString();
        this.price = in.readString();
        this.isUse = in.readBoolean();
    }

    public static final Parcelable.Creator<HomeEntity> CREATOR = new Parcelable.Creator<HomeEntity>() {
        @Override
        public HomeEntity createFromParcel(Parcel source) {
            return new HomeEntity(source);
        }

        @Override
        public HomeEntity[] newArray(int size) {
            return new HomeEntity[size];
        }
    };
}
